<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="月份" prop="month" label-width="120">
        <el-date-picker clearable
                        v-model="queryParams.month"
                        type="month"
                        value-format="yyyyMM"
                        placeholder="请选择月份">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="服务人员" prop="name" label-width="120">
        <el-input v-model="queryParams.userName" clearable>
        </el-input>
      </el-form-item>
      <el-form-item label="服务项目" prop="serviceId" label-width="120">
        <el-select v-model="queryParams.serviceId" placeholder="请选择服务项目" clearable>
          <el-option
            v-for="serviceItem in serviceItemList"
            :key="serviceItem.id"
            :label="serviceItem.itemName"
            :value="serviceItem.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="所在街道" prop="deptId">
      <el-select v-model="queryParams.deptId" placeholder="请选择所在街道" clearable>
        <el-option
          v-for="item in deptList"
          :key="item.deptId"
          :label="item.deptName"
          :value="item.deptId"
        />
      </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['serve:serveTask:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="serveTaskList"  >
      <el-table-column label="老人姓名" align="center" prop="customerName" />
      <el-table-column label="服务人员" align="center" prop="userName" />
      <el-table-column label="所在街道" align="center" prop="deptName" />
      <el-table-column label="服务项目" align="center" prop="serviceName" />
      <el-table-column label="服务签到时间" align="center" prop="signTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.signTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="服务完成时间" align="center" prop="finishTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.finishTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="老人电话" align="center" prop="customerMobile" />
      <el-table-column label="老人住址" align="center" prop="customerAddress" />


    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listServiceLog} from "@/api/report/serviceLog";
import { listDept } from "@/api/system/dept";
import {listServiceItem} from "@/api/base/serviceItem";
export default {
  name: "ServeTask",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 服务任务表格数据
      serveTaskList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deptId: undefined,
        month: undefined,
      },
      //街道
      deptList:[],
      deptId:undefined,
      serviceItemList:[]
    };
  },
  created() {
    //查询街道
    this.getDeptList();
    //获取路由参数
    const deptId= this.$route.query.deptId;
    const month = this.$route.query.month;
    this.deptId = deptId;
    this.queryParams.month = month;

    this.getServiceItemList();

  },
  methods: {
    //获取服务项目
    getServiceItemList(){
      this.loading = true;
      listServiceItem().then(response => {
        this.serviceItemList = response.data;
        this.loading = false;
      });
    },
    /** 查询服务任务列表 */
    getList() {
      this.loading = true;
      listServiceLog(this.queryParams).then(response => {
        this.serveTaskList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询街道 */
    getDeptList() {
      this.loading = true;
      listDept({parentId:100}).then(response => {
        this.deptList = response.data;

        //选中查询条件中的部门
        if(this.deptId){
          this.queryParams.deptId = parseInt(this.deptId) ;
        }
        this.loading = false;
        //查询服务记录
        this.getList();
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('report/exportServiceLog', {
        ...this.queryParams
      }, `服务记录_${new Date().getTime()}.xlsx`)
    },
    /** 查看任务服务项目 */
    handleTaskItem(row) {
      this.$router.push({ path: '/serve/serveTaskItem/index?taskId=' + row.id})
    },
  }
};
</script>
